<template>
	<view class="main">
		<image class="bg-img" src="/static/img/home/yq_bg.png" mode="scaleToFill"></image>
		<uni-nav-bar fixed left-icon="back" title="邀请好友" color="#FFFFFF" backgroundColor="rgb(254,56,67)" :border="false" statusBar
			@clickLeft="goReturn"></uni-nav-bar>
			
		<view class="content">
			<view class="p1">你的邀请码</view>
			<view class="p1">{{item.invite_code}}</view>
			<view class="code">
				<uqrcode ref="uqrcode" canvas-id="qrcode" :value="item.link" :size="140" v-if="show"></uqrcode>
				<!-- <image class="codeImg" src="" mode="scaleToFill"></image> -->
			</view>
			<view class="btns">
				<button class="btn" type="default" @click="copy">复制邀请码</button>
				<button class="btn" type="default" @click="save">保存二维码</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				item:{
					invite_code:'',
					link:''
				},
				show:false,
				options:{
					auto:true,//自动重绘
					size:20
					
				}
			}
		},
		onLoad() {
			this.queryCode()
		},
		methods: {
			queryCode(){//查询邀请码
				this.$http.get('/v1/get_invite_code',res => {
					this.item = res.data 
					this.show = true
				})
			},
			copy(){
				uni.setClipboardData({
					data: this.item.invite_code,
					success: function(res) {
						console.log('success');
					}
				});
			},
			save(){
				this.$refs.uqrcode.save({
				  success: () => {
				    uni.showToast({
				      icon: 'success',
				      title: '保存成功'
				    });
				  }
				});
			},
			// 返回
			goReturn() {
				uni.navigateBack({
					delta:1
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main{
		// background-image: url('../../static/img/home/yq_bg.png');
		// background-size: 100% 100%;
		// position: fixed;
		// width: 100%;
		// height: 100%;
		// top: 0;
		// left: 0;
		// z-index: -1;
	}
	.bg-img{
		 position: fixed;
		 width: 100%;
		 height: 100%;
		 top: 0;
		 left: 0;
		 z-index: -1;
	}
	.content{
		width: 690upx;
		height: 520upx;
		position: fixed;
		bottom: 30upx;
		background-color: $whiteColor;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		border-radius: 30upx;
		.p1{
			color: #333333;
			font-size: 32upx;
			height: 60upx;
			line-height: 60upx;
		}
		.code{
			width: 280upx;
			height: 280upx;
			.codeImg{
				width: 100%;
				height: 100%;
			}
		}
		.btns{
			margin-top: 20upx;
			display: flex;
			width: 500upx;
			justify-content: space-between;
			.btn{
				height: 60upx;
				line-height: 60upx;
				font-size: 28upx;
				border-radius: 30upx;
			}
		}
	}
</style>
